package swle.xyz.austers.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import java.util.Objects;

import swle.xyz.austers.R;
import swle.xyz.austers.myclass.CurrentUser;
import swle.xyz.austers.room.User;
import swle.xyz.austers.room.UserDao;
import swle.xyz.austers.room.UserDataBase;
import swle.xyz.austers.room.UserRoom;

public class PersonalInfoActivity extends BaseActivity {

    private Toolbar toolbar;
    private TextView textView_name;
    private TextView textView_organization;
    private TextView textView_major;
    private TextView textView_sex;
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_info);
        handler = new Handler();
        initView();
        initEvent();
    }
    @Override
    public void initView() {
        toolbar = findViewById(R.id.toolbar_personal_info_activity);
        setSupportActionBar(toolbar); //将toolbar设置为当前activity的操作栏
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);//添加默认的返回图标
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        getSupportActionBar().setDisplayShowTitleEnabled(false);//隐藏toolbar默认显示的label

        textView_name = findViewById(R.id.textView23);
        textView_organization = findViewById(R.id.textView27);
        textView_major = findViewById(R.id.textView29);
        textView_sex = findViewById(R.id.textView25);


    }

    @Override
    public void initEvent() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                UserDataBase userDataBase = UserRoom.getInstance(getApplicationContext());
                UserDao userDao = userDataBase.getUserDao();
                CurrentUser currentUser = CurrentUser.getInstance();
                final User user = userDao.queryUser(currentUser.phonenumber);
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        textView_name.setText(user.getTrue_name());
                        textView_sex.setText(user.getSex());
                        textView_major.setText(user.getMajor());
                        textView_organization.setText(user.getOrganization());
                    }
                });
            }
        }).start();



    }
}
